<template lang="html">
  <div id="charts">
    <div id="info" :style="{width:'100%',height:'100%'}"></div>
  </div>
</template>

<script>
  import * as Util from '../../../Util'
  import co from 'co'
  import echarts from 'echarts'
  import { HttpResetClass } from 'vue-client'

  let getData = function * (self) {
    let load = new HttpResetClass()
    load.load('POST','rs/sql/sellinggasvalue',
      {data: {startDate: self.startdate, endDate: self.enddate,key:'f_gasproperties'}},
      {resolveMsg: null, rejectMsg: null})
      .then((res) => {
        let arrparams = []
        let gasdata = []
        for (var i = 0; i < res.data.length; i++) {
          let item = {}
          arrparams[i] = res.data[i].name
          item.name = res.data[i].name
          item.value = res.data[i].gas_value
          gasdata.push(item)
        }
        self.set(arrparams,gasdata)
      })
  }
  export default {
    props: {
      startdate: {
        type: String,
        default: Util.toStandardDateString()
      },
      enddate: {
        type: String,
        default: Util.toStandardDateString()
      }
    },
    data () {
      return {
        aparams:['开阀数','关阀数','未知'],
        gdata:[
          {value:335, name:'开阀数'},
          {value:310, name:'关阀数'},
          {value:234, name:'未知'}],
        xc: ''
      }
    },
    methods: {
      set (arrparams,gasdata) {
        this.xc = echarts.init(document.getElementById('info'))
        this.xc.setOption({
          title: {
            text: '阀门信息统计',
            subtext: '数据截止',
            x: 'center'
          },
          tooltip: {
            trigger: 'item',
            formatter: ''
          },
          legend: {
            x: 'left',
            y: 'top',
            data:arrparams
          },
          series : [
            {
              name: '访问来源',
              type: 'pie',
              radius : '55%',
              center: ['50%', '60%'],
              data: gasdata,
              itemStyle: {
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        })
      },
      searchdata () {
        let getGen =getData(this)
        co(getGen)
      }
    },
    ready () {
      this.set(this.aparams,this.gdata)
      //this.searchdata()
    },
    watch: {
      'startdate' (val) {
        this.searchdata()
      },
      'enddate' (val) {
        this.searchdata()
      }
    }

  }
</script>
